<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<!--    <xsl:output method="text"/>-->
    <xsl:output method="xml" indent="yes" name="xml" omit-xml-declaration="yes"/>
    
    <xsl:param name="tableName" select="'jos_content'"/>
    
<!--    <xsl:import href="../manifest-manager.xsl"/>-->
    
    <xsl:template match="/"> 
        <xsl:variable name="docname" select="concat(manifest-content/@name, '-sql-article-joomla.sql')"/>
        <xsl:result-document href="{$docname}">
            <xsl:call-template name="insert_sections"/>
            <xsl:call-template name="insert_categories"/>
            <xsl:call-template name="drop_create_content"/>
            
            INSERT INTO `<xsl:value-of select="$tableName"/>` (`id`,
            `title`, `alias`, `title_alias`, `introtext`, `fulltext`, `state`, `sectionid`, `mask`,
            `catid`, `created`, `created_by`, `created_by_alias`, `modified`, `modified_by`,
            `checked_out`, `checked_out_time`, `publish_up`, `publish_down`, `images`, `urls`,
            `attribs`, `version`, `parentid`, `ordering`, `metakey`, `metadesc`, `access`, `hits`,
            `metadata`) VALUES <xsl:apply-templates/>
        </xsl:result-document>
    </xsl:template>
    
    <xsl:template name="associateSec">
        <xsl:param name="lang"/>
        <xsl:choose>
            <xsl:when test="$lang='es'">
                5
            </xsl:when>
            <xsl:when test="$lang='fr'">
                6
            </xsl:when>
            <xsl:when test="$lang='it'">
                7
            </xsl:when>
        </xsl:choose>
    </xsl:template>
    
    <xsl:template name="associateCat">
        <xsl:param name="lang"/>
        <xsl:choose>
            <xsl:when test="$lang='es'">
                34
            </xsl:when>
            <xsl:when test="$lang='fr'">
                35
            </xsl:when>
            <xsl:when test="$lang='it'">
                36
            </xsl:when>
        </xsl:choose>
    </xsl:template>
    
    <xsl:template match="resource">
        <xsl:variable name="module" select="//manifest-content/@name"/>
        <xsl:variable name="lang" select="ancestor::resources/@identifier"/>
        <xsl:variable name="id">
            <xsl:choose>
                <xsl:when test="count(preceding::resource) lt 51"><xsl:value-of select="count(preceding::resource)"/></xsl:when>
                <xsl:otherwise><xsl:value-of select="count(preceding::resource) + 1"/></xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
        
        
        (<!--<xsl:value-of select="$id"/>-->0, '<xsl:value-of select="@identifier"/>', '<xsl:value-of select="substring-before(substring-after('@href','/'),'.html')"/>', '', 
        
        <xsl:choose>
            <xsl:when test="parent::subpool/@type != 'information' ">
                '{goxslt xml="http://localhost/babel-data/course_intermediate/<xsl:value-of select="$module"/>/<xsl:value-of select="$lang"/>/<xsl:value-of select="concat(@identifier,'.xml')"/>"
                xsl="http://localhost/babel-data/transform/babel-transform-fly.xsl"}'
            </xsl:when>
            <xsl:otherwise>
                <xsl:choose>
                    <xsl:when test="@test='xml'">
                        '{goxslt xml="http://localhost/babel-data/course_intermediate/<xsl:value-of select="$module"/>/<xsl:value-of select="$lang"/>/<xsl:value-of select="concat(@identifier,'.xml')"/>"
                        xsl="http://localhost/babel-data/transform/babel-transform-fly.xsl"}'
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:variable name="pathTo" select="concat('../../information/',$module,'/',$lang,'/',@location)"/>
                        <!--'<xsl:copy-of 
                            select="document($pathTo)"/>'-->
                        '
                        {navBabel page="<xsl:value-of select="@identifier"/>" lang="<xsl:value-of select="$lang"/>" 
                        interm="http://localhost/babel-data/transform/navigation/navigation_solo.xsl" 
                        xsl="http://localhost/babel-data/transform/navigation/navigationroot.xsl"} 
                        fiche information'
                    </xsl:otherwise>
                </xsl:choose>
                
            </xsl:otherwise>
        </xsl:choose>,
        '', 1, <xsl:call-template name="associateSec"><xsl:with-param name="lang" select="$lang"/></xsl:call-template>, 0, <xsl:call-template name="associateCat"><xsl:with-param name="lang" select="$lang"/></xsl:call-template>, '2009-03-17 16:57:48', 62, '', '2009-04-01 17:30:45', 62, 62, '2009-04-01
        17:35:32', '2009-03-17 16:57:48', '0000-00-00 00:00:00', '', '',
        'show_title=\nlink_titles=\nshow_intro=\nshow_section=\nlink_section=\nshow_category=\nlink_category=\nshow_vote=\nshow_author=\nshow_create_date=\nshow_modify_date=\nshow_pdf_icon=\nshow_print_icon=\nshow_email_icon=\nlanguage=\nkeyref=\nreadmore=',
        8, 0, 2, '', '', 0, 36, 'robots=\nauthor=')
        <xsl:if test="count(following::resource) > 0">,</xsl:if>
        <xsl:if test="count(following::resource) = 0">;</xsl:if>
    </xsl:template>
    
    <xsl:template name="drop_create_content">
        DROP TABLE IF EXISTS `jos_content`;
        CREATE TABLE IF NOT EXISTS `jos_content` (
        `id` int(11) unsigned NOT NULL auto_increment,
        `title` varchar(255) NOT NULL default '',
        `alias` varchar(255) NOT NULL default '',
        `title_alias` varchar(255) NOT NULL default '',
        `introtext` mediumtext NOT NULL,
        `fulltext` mediumtext NOT NULL,
        `state` tinyint(3) NOT NULL default '0',
        `sectionid` int(11) unsigned NOT NULL default '0',
        `mask` int(11) unsigned NOT NULL default '0',
        `catid` int(11) unsigned NOT NULL default '0',
        `created` datetime NOT NULL default '0000-00-00 00:00:00',
        `created_by` int(11) unsigned NOT NULL default '0',
        `created_by_alias` varchar(255) NOT NULL default '',
        `modified` datetime NOT NULL default '0000-00-00 00:00:00',
        `modified_by` int(11) unsigned NOT NULL default '0',
        `checked_out` int(11) unsigned NOT NULL default '0',
        `checked_out_time` datetime NOT NULL default '0000-00-00 00:00:00',
        `publish_up` datetime NOT NULL default '0000-00-00 00:00:00',
        `publish_down` datetime NOT NULL default '0000-00-00 00:00:00',
        `images` text NOT NULL,
        `urls` text NOT NULL,
        `attribs` text NOT NULL,
        `version` int(11) unsigned NOT NULL default '1',
        `parentid` int(11) unsigned NOT NULL default '0',
        `ordering` int(11) NOT NULL default '0',
        `metakey` text NOT NULL,
        `metadesc` text NOT NULL,
        `access` int(11) unsigned NOT NULL default '0',
        `hits` int(11) unsigned NOT NULL default '0',
        `metadata` text NOT NULL,
        PRIMARY KEY  (`id`),
        KEY `idx_section` (`sectionid`),
        KEY `idx_access` (`access`),
        KEY `idx_checkout` (`checked_out`),
        KEY `idx_state` (`state`),
        KEY `idx_catid` (`catid`),
        KEY `idx_createdby` (`created_by`)
        ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=51 ;
    </xsl:template>
    
    <xsl:template name="insert_categories"> INSERT INTO `jos_categories` (`id`, `parent_id`,
        `title`, `name`, `alias`, `image`, `section`, `image_position`, `description`, `published`,
        `checked_out`, `checked_out_time`, `editor`, `ordering`, `access`, `count`, `params`) 
        VALUES 
        (34, 0, 'Actividad', '', 'actividad', '', '5', 'left', '', 1, 0, '0000-00-00 00:00:00', NULL, 1, 0, 0, ''),
        (35, 0, 'Activité', '', 'activite', '', '6', 'left', '', 1, 0, '0000-00-00 00:00:00', NULL, 1, 0, 0, ''),
        (36, 0, 'Attivita', '', 'attivita', '', '7', 'left', '', 1, 0, '0000-00-00 00:00:00', NULL, 1, 0, 0, '');
    </xsl:template>
    
    <xsl:template name="insert_sections">
        INSERT INTO `jos_sections` (`id`, `title`, `name`, `alias`, `image`,
        `scope`, `image_position`, `description`, `published`, `checked_out`, `checked_out_time`,
        `ordering`, `access`, `count`, `params`) 
        VALUES (5, 'es', '', 'es', '',
        'content', 'left', '', 1, 0, '0000-00-00 00:00:00', 6, 0, 1, ''),
        (6, 'fr', '', 'fr', '',
        'content', 'left', '', 1, 0, '0000-00-00 00:00:00', 7, 0, 1, ''),
        (7, 'it', '', 'it', '',
        'content', 'left', '', 1, 0, '0000-00-00 00:00:00', 8, 0, 1, ''); 
    </xsl:template>

</xsl:stylesheet>